// page/order/comment.js
var utils = require('../../utils/util.js');
Page({
	data: {
		activeIndex: 0,
		sliderOffset: 0,
		tabs: ["待评价", "已评价"],
		waitEval: [],     //待评价
		hasEval: [],   //已评价  
		userface: "",
		username: "",
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onShow: function (options) {
		var that = this
		var uid = wx.getStorageSync('uid');
		var userface = wx.getStorageSync('img');
		var username = wx.getStorageSync('name');
		var pjfh = wx.getStorageSync('pjfh');
		if (pjfh == 1) {
			this.setData({
				sliderOffset: 188,
				activeIndex: 1
			});
			wx.setStorageSync('pjfh', 0) // 存储
		}
		utils.GET({
			url: 'Order/comment',
			params: {
				uid: 1
			},
			success: function (res) {
				console.log(res.data)
				that.setData({
					waitEval: res.data.w,
					hasEval: res.data.y,
					userface: userface,
					username: username
				})
			},
		})

	},

	tabClick: function (e) {
		this.setData({
			sliderOffset: e.currentTarget.offsetLeft,
			activeIndex: e.currentTarget.id
		});
	},
	previewImage: function (e) {
		wx.previewImage({
			current: e.currentTarget.id, // 当前显示图片的http链接
			urls: this.data.hasEval.imgUrl // 需要预览的图片http链接列表
		})
	},
	deleteList: function (e) {
		var that = this
		var app = getApp()
		var index = e.currentTarget.dataset.index
		var uid = wx.getStorageSync('uid')
		var arr = that.data.hasEval
		wx.showModal({
			title: '提示',
			content: '确定删除这个评价吗？',
			success: function (res) {
				if (res.confirm) {
					for (var i = 0; i <= arr.length - 1; i++) {
						if (i == index) {
							console.log(arr[i]['ogid'])
							console.log(uid)
							wx.request({
								url: app.globalData.host + '&g=App&m=Order&a=delcom', //仅为示例，并非真实的接口地址
								data: { uid: uid, id: arr[i]['ogid'] },
								header: {
									'content-type': 'application/json'
								},
								success: function (res) {
									if (res.data.status) {
										wx.showToast({
											title: '删除成功',
											icon: 'success',
											duration: 2000
										})

									}

								}
							})
							arr.splice(i, 1)
							that.setData({

								hasEval: arr
							})
							break
						}
					}

				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
		})



	},
	upimg: function (e) {
		var i = e.currentTarget.dataset.src
		var d = e.currentTarget.dataset.id
		var that = this
		var arr = that.data.hasEval[i]['imgUrl']
		wx.previewImage({
			current: arr[d], // 当前显示图片的http链接
			urls: arr // 需要预览的图片http链接列表
		})
	}
})